/*
 * @Author: your name
 * @Date: 2021-12-22 19:40:34
 * @LastEditTime: 2021-12-22 21:33:36
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \briup_am\am-server\app\controller\company.js
 */
const { Controller } = require('egg');
const Message = require('../utils/Message')

/**
 * @Controller company-controller:比赛公司相关接口
*/

class CompanyController extends Controller {
      /**
   * @Router get /company/pageQuery
   * @summary 分页查询比赛公司信息
   * @request query string *page
   * @request query string *pageSize
   * @apikey
  */

  async pageQuery () {
    const { ctx, service } = this
    const companysVM = await service.company.pageQuery(ctx.query)

    ctx.body = Message.success(companysVM)
  }
   /**
   * @Router post /company/saveOrUpdate
   * @summary 保存或修改比赛公司信息
   * @request query number id
   * @request query string *race_nane
   * @request query string *location
   * @apikey
  */
    async saveOrUpdate () {
        const { ctx, service } = this
        // 接受用户请求 
        // 获取用户参数 ctx.query 
        // 调用service查询
        await service.company.saveOrUpdate(ctx.query)
        ctx.body = Message.success("操作成功")
      }

       /**
   * @Router delete /company/deleteById
   * @summary 根据id删除球队信息
   * @request query string *id 工程id
   * @apikey
  */

  async deleteById () {
    const { ctx, service } = this
    ctx.validate({
      id: 'string'
    }, ctx.query)
    await service.company.deleteById(ctx.query.id)

    ctx.body = Message.success('删除成功')
  }
/**
   * @Router get /company/bindService
   * @summary 接受球队参加比赛
   * @request query number *company_id 比赛公司id
   * @request query number *team_id 球队id
   * @request query syring *coach 球队教练
   * @request query string *captain 球队队长
   * @request query string team_name 球队名称
   * @apikey
  */

 async bindService () {
    const { ctx, service } = this
    // 参数校验
    ctx.validate({
      company_id: 'string',
      team_id: 'string',
    }, ctx.query)
    await service.company.bindService(ctx.query)

    ctx.body = Message.success('接受成功')
  }

  /**
   * @Router get /company/unbindDevice
   * @summary 拒绝球队参加比赛
   * @request query string *team_id 球队id
   * @request query string *player_id 球员id
   * @apikey
  */
   async unbindDevice () {
    const { ctx, service } = this
    // 参数校验
    ctx.validate({
      team_id: 'string',
      player_id: 'string'
    }, ctx.query)
    // 调用service
    await service.company.unbindDevice(ctx.query)
    // 给出响应
    ctx.body = Message.success('拒绝成功')
  }


      /**
   * @Router get /company/findEngineerDeviceTree
   * @summary 查询比赛球队
   * @request query string team_id 球队id
   * @request query string customer_id 客户id
   * @apikey
  */
  async findEngineerDeviceTree () {
    const { ctx, service } = this
    // 调用service
    const data = await service.company.findEngineerDeviceTree(ctx.query)
    // 给出响应
    ctx.body = Message.success(data)
  }

    }
    module.exports = CompanyController;